      function fext(fname,ext)
      character*80 fname,fext
      character*3 ext
      parameter(n=80)
c
c elimina extensao se existir
c
      fext=fname




      do 10 i=n,1,-1
         if(fext(i:i).eq.'.') then
            fext(i:n)=char(0)
            go to 11
         endif
10    continue
11    continue

      do 20 i=n,1,-1
         if(fext(i:i).ne.' ' .and. fext(i:i).ne.char(0)) then
            fext(i+1:i+4)='.'//ext
            go to 21
         endif
20    continue
      write(*,*) 'error in fext'

21    continue
      return
      end